package priv.yiyuan.example.composite.ticket;

/**
 * 简单工单
 * <p>
 * 组合模式-叶子节点
 *
 * @author YiYuan
 * @data 2025/8/29
 * @apoNote
 */
public class SimpleTicket extends TicketComponent {

    public SimpleTicket(String ticketId, String description) {
        super(ticketId, description);
    }

    @Override
    public void add(TicketComponent component) {
        throw new UnsupportedOperationException("简单工单不能添加子工单");
    }

    @Override
    public void remove(TicketComponent component) {
        throw new UnsupportedOperationException("简单工单没有子工单");
    }

    @Override
    public void process(TicketHandler handler) {

        System.out.println("\n开始处理简单工单: " + description + " (ID: " + ticketId + ")");

        boolean handled = handler.handleTicket(this);

        if (!handled && parent != null) {
            System.out.println("当前处理人无法解决, 向上继工单传递");
            parent.process(handler);
        }

    }

    @Override
    public boolean isCompleted() {
        return status == TicketStatus.COMPLETED;
    }

    @Override
    public void display(String indent) {
        System.out.println(indent + " [简单工单] " + ticketId + ": " + description + " (" + status + ")");
    }
}
